package com.lemon.system.controller;

import com.lemon.core.web.Result;
import com.lemon.system.po.CityPO;
import com.lemon.system.service.ICityService;
import com.lemon.system.dto.CityDTO;

import javax.annotation.Resource;
import javax.annotation.security.PermitAll;

import lombok.extern.log4j.Log4j2;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.lemon.mybatisplus.base.BaseController;

import java.util.Collections;
import java.util.List;

/**
 * 城市表控制层
 *
 * @author 李猛
 * @since 2024-02-11
 */
@Log4j2
@RestController
@RequestMapping("city")
public class CityController extends BaseController<CityPO, CityDTO, ICityService> {
    @Resource
    private ICityService iCityService;

    /**
     * 根据城市ID查询下级城市信息
     *
     * @param id
     * @return
     */
    @PermitAll
    @GetMapping("getChildById/{id}")
    public Result<List<CityPO>> getChildById(@PathVariable("id") Integer id) {
        return Result.ok(iCityService.listByMap(Collections.singletonMap("parent_id", id)));
    }
}